package com.mgr;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.qy.DaoMgr;
import com.qy.bean.DriveLine;
import com.qy.bean.DriveRecord;
import com.qy.bean.Option;
import com.qy.util.StaticData;
import com.qy.util.TimeUtil;
import com.util.DLUtil;

/**
 * 驾驶线路图
 * @author zwl
 * 2018年2月3日
 */
public class DriveLineMgr {

    /**
     * 获取驾驶线路图
     * @param driverOrderId
     * @return
     */
    public static DriveLine getDriveLine(int driverOrderId){
	return DaoMgr.getDriveLineDao().getDriveLineByDoId(driverOrderId);
    }
    /**
     * 转换坐标列表
     * @param line
     * @return
     */
    public static JSONArray turnToList(DriveLine line){
	JSONArray jsa = new JSONArray();
	if(line.getDriveLine()!=null&&!line.getDriveLine().isEmpty()){
	    String[] tmps = line.getDriveLine().split(StaticData.first_split);
	    for(String tmp:tmps){
		jsa.add(tmp);
	    }
	}
	return jsa;
    }
    
    public static void createDL(int odId){
	List<DriveRecord>  list = DaoMgr.getDriveRecordDao().getDriveRecordList(odId);
	double[][] c = new double[list.size()][2];
	DriveRecord tmp = null;
	String[] cTmp = null;
	for(int i=0;i<list.size();i++){
	    tmp = list.get(i);
	    cTmp = tmp.getSite().split(StaticData.second_split);
	    c[i][0] = Double.parseDouble(cTmp[0]);
	    c[i][1] = Double.parseDouble(cTmp[1]);
	}
	DLUtil.changeGpsArray(c);
	
	DriveLine dl = new DriveLine();
	dl.setOp(Option.Insert);
	dl.setDriverOrderId(odId);
	dl.setCreateDate(TimeUtil.getSysteCurTime());
	StringBuilder sb = new StringBuilder();
	for(int i=0;i<c.length;i++){
	    sb.append(c[i][0]).append(StaticData.second_split).append(c[i][1]).append(StaticData.first_split);
	}
	dl.setDriveLine(sb.substring(0, sb.length()-1));
	DaoMgr.getDriveLineDao().createDriveLine(dl);
    }
}
